//
//  IFlyBaseService.m
//  AIKITDemo
//
//  Created by xyzhang on 2023/3/1.
//

#import "IFlyBaseService.h"


@implementation IFlyBaseService

- (void)initSDK :(NSDictionary*) args {
    NSString *APPID = args[@"APPID"];
    NSString *APIKEY = args[@"APIKEY"];
    NSString *APISECRET = args[@"APISECRET"];
    log(@"SDK初始化中...");
////    [AiHelper setConfig:@"host" value:@"http://aitest.iflyaicloud.com:8000"];
    int ret = [ILibrary initSDK:^(AiHelperMaker *maker) {
        maker.appId(APPID).apiKey(APIKEY).apiSecret(APISECRET);
    }];
    if (ret == 0) {
        log(@"SDK 初始化成功！");
        _initSDK = YES;
        [AiHelper registerAppCallback:self];
//        [AiHelper shareInstance].delegate = self;
    } else {
        log(@"SDK 初始化失败，ret: %d", ret);
        return;
    }

}

- (void)initEngine:(NSString *)abilityId {
    log(@"引擎初始化中...");
    int code = [AiHelper initEngine:abilityId param:nil];
    if (code == 0) {
        log(@"引擎初始化成功！");
        _initEngine = YES;
//        [self changeServiceStateAndNotifyDelegate:IFlyTTSServiceStateInit];
    } else {
        log(@"引擎初始化失败，code: %d", code);
    }
}

- (void)initEngine:(NSString *)abilityId engineParams:(nullable AIKITParameters *)engineParams {
    log(@"引擎初始化中...");
    int code = [AiHelper initEngine:abilityId param:engineParams];
    if (code == 0) {
        log(@"引擎初始化成功！");
        _initEngine = YES;
    } else {
        log(@"引擎初始化失败，code: %d", code);
    }
}

- (void)unInitSDK {
    int ret = [ILibrary unInit];
    if (ret == 0) {
        //逆初始化成功
        _initSDK = NO;
        [AiHelper shareInstance].delegate = nil;
        log(@"引擎逆初始化成功！");
    }
    else {
        log(@"引擎逆初始化失败！code: %d", ret);
    }
}



@end
